package com.jp.refreshlocalcacheserver.net.netty;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

/**
 * @Author: jipeng
 * @Description:
 * @Date: Created in 2020/5/14 15:47
 */
public class EchoServerHandlerInitializer extends ChannelInitializer<SocketChannel> {

    public static String delimiter = "_$";

    @Override
    protected void initChannel(SocketChannel ch)  {
        ChannelPipeline pipeline = ch.pipeline();

        pipeline.addLast(new DelimiterBasedFrameDecoder(1024,
                Unpooled.wrappedBuffer(delimiter.getBytes())));

        pipeline.addLast(new StringDecoder());

        pipeline.addLast(new StringEncoder());

        pipeline.addLast(new EchoServerHandler());
    }
}
